<?php
// @formatter:off
/**
 * @file 3.php
 * @author Alejandro Dario Simi
 * @date $Date: 2013-06-07 02:16:25 +0000 (Fri, 07 Jun 2013) $
 *
 * $Id: 3.php 71 2013-06-07 02:16:25Z daemonraco@gmail.com $
 * $URL: http://wcomix.googlecode.com/svn/tags/wcomix-1.0-BETA1/install/steps/3.php $
 */
// @formatter:on

if(defined("__INSTALLER__")) {
	if(is_readable($wcPaths["config-local"]) || is_readable($wcPaths["install-tmps"]["defaults"])) {
		echo "\t\t\t\t<p>Defaults already configured.</p>\n";
		$isOkToReload = true;
	} else {
		if($_SERVER["REQUEST_METHOD"] != "POST") {
			echo "\t\t\t\t<p>This is step {$wciStepCheck}. Here you will configure many default values. But, you can skip this part leaving just by clicking \"Send\", in such\n";
			echo "\t\t\t\tcase, recommended values and default names will be taken.</p>\n";
			echo "\t\t\t\t<p><form action=\"#\" method=\"post\">\n";
			echo "\t\t\t\t\t<ul>\n";

			echo "\t\t\t\t\t\t<li>Root e-mail <input type=\"input\" id=\"ST_EMAIL\" name=\"ST_EMAIL\" value=\"".(DIRECTORY_SEPARATOR=="/"?exec('whoami'):"webmaster")."@{$_SERVER["SERVER_NAME"]}\"/></li>\n";
			echo "\t\t\t\t\t\t<li>Site Name <input type=\"input\" id=\"ST_NAME\"    name=\"ST_NAME\" value=\"{$wcSite["name"]}\"/></li>\n";
			echo "\t\t\t\t\t\t<li>Site Wiki <input type=\"input\" id=\"ST_WIKI\"    name=\"ST_WIKI\" value=\"\"/></li>\n";

			echo "\t\t\t\t\t\t<li><input type=\"checkbox\" id=\"DF_PAGECACHE\"   name=\"DF_PAGECACHE\"/> Use page cache system (experimental).</li>\n";
			echo "\t\t\t\t\t\t<li><input type=\"checkbox\" id=\"DF_PUBLICGROUP\" name=\"DF_PUBLICGROUP\" checked=\"checked\"/> Allow public groups for anonymous users.</li>\n";
			echo "\t\t\t\t\t\t<li>Maximum session duration (in seconds) <input type=\"input\" id=\"DF_SESSIONMAX\"  name=\"DF_SESSIONMAX\" value=\"86400\"/></li>\n";

			echo "\t\t\t\t\t\t<li>Home page: <select id=\"DF_ACTION\" name=\"DF_ACTION\">\n";
			echo "\t\t\t\t\t\t\t<option value=\"WC_ACTION_RANDOM\" selected=\"selected\">Show Random Comics</option>\n";
			echo "\t\t\t\t\t\t\t<option value=\"WC_ACTION_COLLECTION_LIST\">Show All Collections</option>\n";
			echo "\t\t\t\t\t\t\t<option value=\"WC_ACTION_TAG_LIST\">Show All Tags</option>\n";
			echo "\t\t\t\t\t\t\t<option value=\"WC_ACTION_DIRECTORY_LIST\">Show All Directories</option>\n";
			echo "\t\t\t\t\t\t\t<option value=\"WC_ACTION_NOTHING\">Nothing</option>\n";
			echo "\t\t\t\t\t\t</select></li>\n";

			echo "\t\t\t\t\t\t<li>Mobile home page: <select id=\"DF_MACTION\" name=\"DF_MACTION\">\n";
			echo "\t\t\t\t\t\t\t<option value=\"WC_ACTION_LOGO\" selected=\"selected\">Show Logotype</option>\n";
			echo "\t\t\t\t\t\t\t<option value=\"WC_ACTION_MENU\">Show menu</option>\n";
			echo "\t\t\t\t\t\t\t<option value=\"WC_ACTION_COLLECTION_LIST\">Show All Collections</option>\n";
			echo "\t\t\t\t\t\t\t<option value=\"WC_ACTION_TAG_LIST\">Show All Tags</option>\n";
			//echo "\t\t\t\t\t\t\t<option value=\"WC_ACTION_DIRECTORY_LIST\">Show All
			// Directories</option>\n";
			echo "\t\t\t\t\t\t</select></li>\n";

			echo "\t\t\t\t\t\t<li><input type=\"checkbox\" id=\"DF_AGGRESSIVE\" name=\"DF_AGGRESSIVE\" checked=\"checked\"/> Database aggressive policy. Anihilate every unknown object on the data base. If you are a developer you may want this option to be unchecked.</li>\n";

			echo "\t\t\t\t\t</ul>\n";
			echo "\t\t\t\t\t<input type=\"submit\" value=\"Send\"/>\n";
			echo "\t\t\t\t\t<input type=\"reset\"  value=\"Reset\"/>\n";
			echo "\t\t\t\t</form></p>\n";

			$isOkToContinue = false;
			$isOkToReload = false;
		} else {
			$aux = "<?php\n";
			$aux .= "\$wcSite[\"name\"]	= \"".(strlen($_POST["ST_NAME"]) ? $_POST["ST_NAME"] : $wcSite["name"])."\";\n";
			$aux .= "\$wcSite[\"email\"]	= \"".(strlen($_POST["ST_EMAIL"]) ? $_POST["ST_EMAIL"] : $wcSite["email"])."\";\n";
			$aux .= "\$wcSite[\"wiki\"]	= ".(strlen($_POST["ST_WIKI"]) ? "\"{$_POST["ST_WIKI"]}\"" : "false").";\n";
			$aux .= "\n";
			$aux .= "\$wcDatabase[\"aggressive\"]	= ".(isset($_POST["DF_AGGRESSIVE"]) ? "true" : "false").";\n";
			$aux .= "\n";
			$aux .= "\$wcDefaults[\"page-cache\"]	= ".(isset($_POST["DF_PAGECACHE"]) ? "true" : "false").";\n";
			$aux .= "\$wcDefaults[\"public-group\"]	= ".(isset($_POST["DF_PUBLICGROUP"]) ? "true" : "false").";\n";
			$aux .= "\$wcDefaults[\"session-max-time\"]	= ".(strlen($_POST["DF_SESSIONMAX"]) ? "{$_POST["DF_SESSIONMAX"]}" : "86400").";\n";
			$aux .= "\$wcDefaults[\"action\"]		= \"".(strlen($_POST["DF_ACTION"]) ? "{$_POST["DF_ACTION"]}" : "false")."\";\n";
			$aux .= "\$wcDefaults[\"mobile-action\"]	= \"".(strlen($_POST["DF_MACTION"]) ? "{$_POST["DF_MACTION"]}" : "false")."\";\n";
			$aux .= "?>\n";

			file_put_contents($wcPaths["install-tmps"]["defaults"], $aux);

			echo "\t\t\t\t<p>[OK:Defaults accepted.]</p>\n";

			$isOkToContinue = true;
			$isOkToReload = true;
		}
	}
}
?>